package com.hfzy.ihk.web.freeswitchManage.controller;

import com.hfzy.ihk.facade.freeswitchManage.entity.Gateway;
import com.hfzy.ihk.facade.freeswitchManage.enums.CompanyEnum;
import com.hfzy.ihk.facade.freeswitchManage.enums.SlotStateEnum;
import com.hfzy.ihk.web.freeswitchManage.mapper.GatewayCardSlotMapper;
import com.hfzy.ihk.web.freeswitchManage.vo.GatewayCardSlotVo;
import com.hfzy.ihk.web.oauth.client.table.PageTableHandler;
import com.hfzy.ihk.web.oauth.client.table.PageTableRequest;
import com.hfzy.ihk.web.oauth.client.table.PageTableResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * Created by czs on 2019/4/1.
 */
@RestController
@RequestMapping("/gatewayCardSlot")
@Slf4j
public class GatewayCardSlotController {

    @Autowired
    GatewayCardSlotMapper gatewayCardSlotMapper;

    @RequestMapping("page")
    public ModelAndView page(ModelAndView modelAndView){
        modelAndView.setViewName("page/gatewayCardSlot/gatewayCardSlotList");
        //卡槽状态枚举
        modelAndView.addObject("slotStates", SlotStateEnum.values());
        modelAndView.addObject("belongCompanys",CompanyEnum.values());
        return modelAndView;

    }

    @RequestMapping("listGatewayCardSlots")
    public PageTableResponse listGatewayCardSlots(PageTableRequest request) {
        request.setOffset((request.getOffset()-1)*request.getLimit());
        return new PageTableHandler(new PageTableHandler.CountHandler() {

            @Override
            public int count(PageTableRequest request) {

                return gatewayCardSlotMapper.count(request.getParams());
            }
        }, new PageTableHandler.ListHandler() {

            @Override
            public List<GatewayCardSlotVo> list(PageTableRequest request) {
                List<GatewayCardSlotVo> list = gatewayCardSlotMapper.list(request.getParams(), request.getOffset(), request.getLimit());
                return list;
            }
        }).handle(request);
    }
}
